package cn.singno.bob.web.security;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.support.RequestDataValueProcessor;

import com.google.common.collect.Maps;

/**
 * form:form 表单渲染
 * @author 鲍建明
 *
 */
public class CsrfRequestDataValueProcessor implements RequestDataValueProcessor {

	public Map<String, String> getExtraHiddenFields(HttpServletRequest request) {
		//此处是当使用spring的taglib标签<form:from>创建表单时候，增加的隐藏域参数
		Map<String, String> hiddenFields = Maps.newHashMap();
		hiddenFields.put(CsrfTokenManager.CSRF_PARAM_NAME, CsrfTokenManager.createTokenForSession(request.getSession()));
		return hiddenFields;
	}

	public String processAction(HttpServletRequest request, String action) {
		//TODO 暂时原样返回action
		return action;
	}

	public String processFormFieldValue(HttpServletRequest request, String name,
			String value, String type) {
		// TODO 暂时原样返回value
		return value;
	}

	public String processUrl(HttpServletRequest request, String url) {
		// TODO 暂时原样返回url
		return url;
	}

	@Override
	public String processAction(HttpServletRequest arg0, String action,
			String arg2) {
		// TODO Auto-generated method stub
		return action;
	}

}
